#include "extra_sheiyi.h"

static lv_style_t style_box;
extern lv_group_t *key_group; //键盘组
extern TaskMgr task_mgr;

static void extraCall(struct _lv_obj_t *obj, lv_event_t event){ //选择推箱子关卡的回调函数
        if (event == LV_EVENT_KEY) {
        const uint32_t *key = lv_event_get_data();
        UART_printf(&huart1,"\r\nevent = %d *key=%d\n",event,*key);
        if (*key == LV_KEY_UP) {
            ;
        } else if (*key == LV_KEY_DOWN) {
            ;
        } else if (*key == LV_KEY_LEFT) {
            ;
        } else if (*key == LV_KEY_RIGHT) {
            ;
        } else if (*key == LV_KEY_ENTER) {
            task_mgr.BackTo_CG_request = 1;
        } else if (*key == LV_KEY_HOME) { //回到上一界面，即回到选择游戏界面
            task_mgr.BackTo_CG_request = 1;
        }
    }
}

lv_obj_t * createExtra()
{
    //样式
    lv_style_reset(&style_box);
    lv_style_set_value_align(&style_box, LV_STATE_DEFAULT, LV_ALIGN_OUT_TOP_LEFT);
    lv_style_set_value_ofs_y(&style_box, LV_STATE_DEFAULT, -LV_DPX(10));
    lv_style_set_margin_top(&style_box, LV_STATE_DEFAULT, LV_DPX(20));
    lv_style_set_bg_opa(&style_box, LV_STATE_DEFAULT, LV_OPA_50);

    //用于装载的对象
    lv_obj_t* mainPage = lv_obj_create(lv_scr_act(), NULL);
    lv_obj_set_style_local_radius(mainPage, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, 0);
    //lv_obj_set_style_local_bg_color(mainPage, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLUE);
    lv_obj_set_pos(mainPage, 0, 0);
    lv_obj_set_width(mainPage, 800);
    lv_obj_set_height(mainPage, 480);
    //底图
    lv_obj_t* imgGirl = lv_img_create(mainPage, NULL);
    lv_img_set_src(imgGirl, "F:/extra.bin");

    //底图上面创造容器
    lv_obj_t *cont = lv_cont_create(mainPage, NULL);
    lv_cont_set_layout(cont, LV_LAYOUT_COLUMN_LEFT);
    lv_obj_add_style(cont, LV_CONT_PART_MAIN, &style_box);
    lv_cont_set_fit2(cont, LV_FIT_NONE, LV_FIT_TIGHT);
    lv_obj_set_style_local_value_str(cont, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, "Memeber Info");
    lv_obj_set_width(cont, 700);
    lv_obj_set_pos(cont, 50, 50);

    //标签
    lv_obj_t* label = lv_label_create(cont, NULL);
    lv_obj_set_style_local_text_font(label, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT ,&lv_font_montserrat_24);
    lv_label_set_text(label, "This is the info page of the project.");

    label = lv_label_create(cont, NULL);
    lv_obj_set_style_local_text_font(label, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT ,&lv_font_montserrat_24);
    lv_label_set_text(label, "We are from CAST,locating in 4-314");

    label = lv_label_create(cont, NULL);
    lv_obj_set_style_local_text_font(label, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT ,&lv_font_montserrat_24);
    lv_label_set_text(label, "Member: sheiyi, lby(cyberfucker), yzj");

    label = lv_label_create(cont, NULL);
    lv_obj_set_style_local_text_font(label, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT ,&lv_font_montserrat_24);
    lv_label_set_text(label, "Based on stm32f407vet6, Using lvgl");

    label = lv_label_create(cont, NULL);
    lv_obj_set_style_local_text_font(label, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT ,&lv_font_montserrat_24);
    lv_label_set_text(label, "The project is opensourced on gitee:");

    label = lv_label_create(cont, NULL);
    lv_obj_set_style_local_text_font(label, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT ,&lv_font_montserrat_24);
    lv_label_set_text(label, "https://gitee.com/bdrf-lby/stm32-f407_-lvgl");

    //按钮
    lv_obj_t* btn = lv_btn_create(cont, NULL);
    lv_btn_set_fit2(btn, LV_FIT_NONE, LV_FIT_TIGHT);
    lv_obj_set_width(btn, 350);
    //将图形按钮加入到组中
    lv_group_add_obj(key_group, btn);
    lv_obj_set_event_cb(btn, extraCall);//按钮的事件
    //按钮标签
    label = lv_label_create(btn, NULL);
    lv_btn_toggle(btn);
    lv_label_set_text(label, "Return->");

    return mainPage;
}